import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_category.dart';
import 'package:flutter_learn_vi/src/page/topic/topic_select_page.dart';
import 'package:flutter_learn_vi/src/utils/navigator_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/12.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///答题主页面
class TopicCatarSelectTwoPage extends StatefulWidget {
  final String pageTitle;
  final List<String> nodeValues;

  TopicCatarSelectTwoPage({this.nodeValues, this.pageTitle});

  @override
  _TestPageState createState() => _TestPageState();
}

class _TestPageState extends State<TopicCatarSelectTwoPage> {
  CategoryBean categoryBean;

  List<CategoryBean> _list = [];

  @override
  void initState() {
    super.initState();
    widget.nodeValues.forEach((element) {
      List<String> split = element.split(":");
      _list.add(CategoryBean(categoryName: split[1], categoryCode: split[0]));
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text("请选择"),
      ),
      body: Container(
        color: Colors.grey[200],
        child: ListView.builder(
          itemBuilder: (BuildContext context, int index) {
            CategoryBean bean = _list[index];
            return Container(
              margin: EdgeInsets.only(top: 2),
              color: Colors.white,
              child: ListTile(
                onTap: () {
                  NavigatorUtils.pushPage(
                      context,
                      TopicSelectPage(
                        pageTitle: "${bean.categoryName}",
                        categoryOne: bean.categoryCode,
                      ),
                      isReplace: true);
                },
                leading: ClipOval(
                  child: Container(
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Colors.blueGrey.withOpacity(0.5),
                    ),
                    width: 20,
                    height: 20,
                    child: Text("${index + 1}"),
                  ),
                ),
                title: Text("${bean.categoryName}"),
                trailing: Icon(Icons.arrow_forward_ios),
              ),
            );
          },
          itemCount: _list.length,
        ),
      ),
    );
  }
}
